		TITLE	INSTFLNM - Copyright (C) 1994 SLR Systems

		INCLUDE	MACROS

if	fg_cvpack

		INCLUDE	CVSTUFF

		PUBLIC	INSTALL_FILEINDEX_SPACE


		.DATA

		EXTERNDEF	SYMBOL_TEXT:BYTE

		EXTERNDEF	SYMBOL_LENGTH:DWORD,FIRST_RELOC_GINDEX:DWORD,LAST_RELOC_GINDEX:DWORD

		EXTERNDEF	RELOC_GARRAY:STD_PTR_S,RELOC_STUFF:ALLOCS_STRUCT,SYMBOL_TPTR:TPTR_STRUCT


		.CODE	CVPACK_TEXT

		EXTERNDEF	COMMON_INST_INIT:PROC,RELOC_POOL_GET:PROC,CASE_STRING_COMPARE_HARD:PROC,MOVE_PNAME:PROC
		EXTERNDEF	MOVE_ASCIZ_ECX_EAX:PROC


CV_NAMESP_INIT	PROC	PRIVATE
		;
		;
		;
		PUSH	EAX
		MOV	EAX,OFF RELOC_STUFF

		CALL	COMMON_INST_INIT

		XOR	EAX,EAX
		MOV	EBX,RELOC_STUFF.ALLO_HASH_TABLE_PTR

		MOV	FIRST_RELOC_GINDEX,EAX
		MOV	LAST_RELOC_GINDEX,EAX

		POP	EAX
		JMP	INIT_RET

CV_NAMESP_INIT	ENDP


INSTALL_FILEINDEX_SPACE	PROC
		;
		;EAX IS HASH, ECX IS TEXT
		;
		;RETURN EAX = OFFSET IN NAMESPACE
		;
		PUSHM	EBX,EAX

		MOV	EAX,OFF SYMBOL_TEXT
		CALL	MOVE_ASCIZ_ECX_EAX

		SUB	EAX,OFF SYMBOL_TEXT
		MOV	EBX,RELOC_STUFF.ALLO_HASH_TABLE_PTR

		MOV	SYMBOL_LENGTH,EAX
		TEST	EBX,EBX

		POP	EAX
		JZ	CV_NAMESP_INIT
INIT_RET::
		XOR	EDX,EDX
		MOV	ECX,EAX

		HASHDIV	RELOC_STUFF.ALLO_HASH		;DX IS HASH VALUE

		PUSHM	ESI,EDI

		MOV	EAX,DPTR [EBX+EDX*4]
		LEA	EBX,[EBX+EDX*4 - CV_NAMESP_STRUCT._CNS_NEXT_HASH_GINDEX]
NAME_NEXT:
		TEST	EAX,EAX
		JZ	DO_INSTALL

		MOV	EDX,EAX
		CONVERT	EAX,EAX,RELOC_GARRAY
		ASSUME	EAX:PTR CV_NAMESP_STRUCT
		MOV	EBX,EAX
		ASSUME	EBX:PTR CV_NAMESP_STRUCT
		;
		;PROBABLE MATCH, NEED COMPARE...
		;
		MOV	EDI,[EAX]._CNS_HASH
		MOV	EAX,[EAX]._CNS_NEXT_HASH_GINDEX

		CMP	ECX,EDI				;HASH MATCH?
		JNZ	NAME_NEXT

		PUSH	ECX
		MOV	ECX,SYMBOL_LENGTH

		MOV	EDI,OFF SYMBOL_TEXT
		LEA	ESI,[EBX]._CNS_TEXT

		MOV	EAX,[EBX]._CNS_NEXT_HASH_GINDEX
		CALL	CASE_STRING_COMPARE_HARD

		POP	ECX
		JNZ	NAME_NEXT

		POPM	EDI,ESI

		MOV	EAX,[EBX]._CNS_OFFSET
		POP	EBX

		RET

DO_INSTALL:
		;
		;EBX GETS POINTER...
		;
		MOV	EAX,SYMBOL_LENGTH
		MOV	ESI,EBX

		ADD	EAX,SIZE CV_NAMESP_STRUCT-3		;
		CALL	RELOC_POOL_GET			;ES:DI IS PHYS, AX LOG

		MOV	EDI,EAX
		INSTALL_POINTER_GINDEX	RELOC_GARRAY
		MOV	[ESI].CV_NAMESP_STRUCT._CNS_NEXT_HASH_GINDEX,EAX

		MOV	EBX,LAST_RELOC_GINDEX
		MOV	LAST_RELOC_GINDEX,EAX

		TEST	EBX,EBX
		JZ	L2$

		MOV	[EBX]._CNS_NEXT_GINDEX,EAX
L3$:
		MOV	EBX,EDI

		MOV	EDX,EAX
		MOV	ESI,ECX

		MOV	ECX,CV_NAMESP_STRUCT._CNS_TEXT/4
		XOR	EAX,EAX

		REP	STOSD

		MOV	[EBX]._CNS_HASH,ESI
		MOV	ECX,SYMBOL_LENGTH

		MOV	ESI,OFF SYMBOL_TEXT
		MOV	EDX,ECX

		SHR	ECX,2
		INC	EDX

		INC	ECX
		MOV	EAX,CNS_OFFSET

		OPTI_MOVSD

		ADD	EDX,EAX
		MOV	[EBX]._CNS_OFFSET,EAX

		POPM	EDI,ESI

		POP	EBX
		MOV	CNS_OFFSET,EDX

		RET

L2$:
		MOV	FIRST_RELOC_GINDEX,EAX
		JMP	L3$

INSTALL_FILEINDEX_SPACE	ENDP


		.DATA?

CNS_OFFSET	DD	?

endif


		END

